package com.awcall.iot.config;

import com.awcall.iot.interceptor.AuthInterceptor;
import com.awcall.iot.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public AuthInterceptor authInterceptor() {
        return new AuthInterceptor();
    }

    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/admin/systemUser/updatep")
                .excludePathPatterns("/admin/setting/*")
                .excludePathPatterns("/admin/total/*")
                .excludePathPatterns("/admin/verifCode/*");
        registry.addInterceptor(authInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/admin/verifCode/*")
                .excludePathPatterns("/admin/systemUser/updatep")
                .excludePathPatterns("/admin/total/*")
                .excludePathPatterns("/admin/setting/*")
                .excludePathPatterns("/admin/login");
        super.addInterceptors(registry);
    }

}
